package com.dgut.app.controller;

import com.dgut.app.service.TypeService;
import com.dgut.common.utils.R;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zyq
 * @Date 2022/4/14 23:12
 * @Description TODO
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/app/type")
@RequiredArgsConstructor
public class TypeController {

    private final TypeService typeService;

    /**
     * 返回所有类别
     */
    @GetMapping("/category")
    @PreAuthorize("hasAnyRole('1,2')")
    public R listAllCategory() {
        return R.ok().data(typeService.listAllCategory());
    }

    /**
     * 根据类别返回回收物列表
     */
    @GetMapping("/item/{categoryId}")
    @PreAuthorize("hasAnyRole('1,2')")
    public R listItemByCategory(@PathVariable("categoryId") Integer categoryId) {
        return R.ok().data(typeService.listItemByCategory(categoryId));
    }

}
